package com.fare.taluo.core.domain.queue.message;

import javax.persistence.Column;
import javax.persistence.Table;

import com.dayatang.domain.InstanceFactory;
import com.fare.taluo.core.domain.queue.QueueBaseEntity;
import com.fare.taluo.core.domain.queue.QueueBaseRepository;
import com.fare.taluo.core.domain.queue.message.repository.impl.QueueRegisterEmailInfoRepositoryImpl;
import com.fare.taluo.message.SendEmail;

@javax.persistence.Entity
@Table(name="que_register_email_info")
public class QueueRegisterEmailInfoEntity extends QueueBaseEntity<QueueRegisterEmailInfoEntity> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 发送人地址
	 */
	@Column(name = "FROM_ADDRESS")
	private String fromAddress;
	/**
	 * 接收人地址，多个以分号分隔
	 */
	@Column(name = "TO_ADDRESS")
	private String toAddress;
	
	/**
	 * 抄送人地址，多个以分号分隔
	 */
	@Column(name = "COPYTO_ADDRESS")
	private String copyToAddress;
	
	/**
	 * 主题 
	 */
	@Column(name = "SUBJECT")
	private String subject;
	/**
	 * 内容
	 */
	@Column(name = "BODY")
	private String body;
	

	public String getFromAddress() {
		return fromAddress;
	}

	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
	}

	public String getToAddress() {
		return toAddress;
	}

	public void setToAddress(String toAddress) {
		this.toAddress = toAddress;
	}

	public String getCopyToAddress() {
		return copyToAddress;
	}

	public void setCopyToAddress(String copyToAddress) {
		this.copyToAddress = copyToAddress;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	
	@Override
	protected QueueBaseRepository<QueueRegisterEmailInfoEntity> getEntityRepository() {
		return InstanceFactory.getInstance(QueueRegisterEmailInfoRepositoryImpl.class);
	}

	@Override
	public QueueBaseEntity<QueueRegisterEmailInfoEntity> createNextTask(Long id)
			throws Exception {
		if(logger.isDebugEnabled()){
			logger.debug("邮件队列，不需要周期性创建下一个任务");
		}
		return null;
	}

	@Override
	public void executeTask(Long id) throws Exception {
		QueueRegisterEmailInfoEntity entity = getEntityRepository().get(this.getClass(), id);
			if(entity != null){
				new SendEmail()
				.setTo(entity.getToAddress())
				.setSubject(entity.getSubject())
				.setBody(entity.getBody())
				.send();
			}
		
	}
}
